/**
 * add trim function to String.
 */
String.prototype.trim = function()
{
	return this.replace(/^\s+/g,"").replace(/\s+$/g,"");
}

/**
 * check whether the str is empty, (undifined, null, '', '    ')
 * @param str
 * @return	boolean		ture if str is empty ; otherwise return false;
 */
function isEmpty(str)
{
	if(!str || str == '' || str.length <= 0 || str.trim().length <= 0)
    {
        return true;
    }
    return false;
}
/**
 * check whether the str is valid email, if empty, return true.
 * @param str
 * @return	if is a valid email , return true.
 */
function isEmail(str)
{
	if(isEmpty(str))
	{
		return true;
	}
    var regex = /^[\w\.\-]+@([\w\-]+\.)+[\w\-]+$/;
    var reg = new RegExp(regex); 
    return !(str.match(reg) == null);
}

/**
 * check whether the str is integer , if empty, return true;
 */
function isInteger(str)
{
	if(isEmpty(str))
	{
		return true;
	}
	return (/^(\-?)(\d+)$/.test(str));
}

/**
 * common show dialog,
 * @param info , the alert message
 */
var commonDialog;
function CommonAlert(info, param)
{
    if(!param)
    {
        param = {};
    }
	if(!commonDialog)
    {
        var title = param.title || 'Alert';
		$($(document).children().get(0)).append("<div id='commonDialog' style='display:none' title='" + title + "'></div>");
        $('#commonDialog').html(info);
        commonDialog = $("#commonDialog").dialog
        ({
        	height: param.height,
            width: param.width,
            resizable: param.resizable || false,
            modal: param.modal || true,
            buttons : 
            {
                'OK': function() 
                {
                    $(this).dialog("close");
                }
            }
        });
    }
    else
    {
    	$('#commonDialog').html(info);
        commonDialog.dialog("open");
    }
}